package com.ruoyi.web.controller.train;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.MentorClassify;
import com.ruoyi.system.service.IMentorClassifyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 导师分类Controller
 *
 * @author dp
 * @date 2023-11-27
 */
@Api(tags = {"导师分类"})
@RestController
@RequestMapping("/mentor/classify")
public class MentorClassifyController extends BaseController {
    @Autowired
    private IMentorClassifyService mentorClassifyService;
    @Autowired
    TokenService tokenService;

    /**
     * 查询导师分类列表
     */
    @ApiOperation(value = "导师分类列表", notes = "查询导师分类列表详情", tags = {"导师分类管理"})
    //@PreAuthorize("@ss.hasPermi('mentor:classify:list')")
    @GetMapping("/list")
    public TableDataInfo list(MentorClassify mentorClassify) {
        startPage();
        List<MentorClassify> list = mentorClassifyService.selectMentorClassifyList(mentorClassify);
        return getDataTable(list);
    }

    /**
     * 导出导师分类列表
     */
    @ApiOperation(value = "导师分类列表导出", notes = "导出导师分类列表", tags = {"导师分类管理"})
    //@PreAuthorize("@ss.hasPermi('mentor:classify:export')")
    @Log(title = "导师分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MentorClassify mentorClassify) {
        List<MentorClassify> list = mentorClassifyService.selectMentorClassifyList(mentorClassify);
        ExcelUtil<MentorClassify> util = new ExcelUtil<MentorClassify>(MentorClassify.class);
        util.exportExcel(response, list, "导师分类数据");
    }

    /**
     * 获取导师分类详细信息
     */
    @ApiOperation(value = "获取导师分类详细信息", notes = "获取导师分类详细信息详情", tags = {"导师分类管理"})
    //@PreAuthorize("@ss.hasPermi('mentor:classify:query')")
    @GetMapping(value = "/{mentorClassifyId}")
    public AjaxResult getInfo(@PathVariable("mentorClassifyId") Long mentorClassifyId) {
        return success(mentorClassifyService.selectMentorClassifyByMentorClassifyId(mentorClassifyId));
    }

    /**
     * 新增导师分类
     */
    @ApiOperation(value = "新增导师分类", notes = "新增导师分类详情", tags = {"导师分类管理"})
    //@PreAuthorize("@ss.hasPermi('mentor:classify:add')")
    @Log(title = "导师分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(HttpServletRequest request, @RequestBody MentorClassify mentorClassify) {
        Long userId = tokenService.getLoginUser(request).getUser().getUserId();
        mentorClassifyService.completeData(mentorClassify, userId, 1);
        return toAjax(mentorClassifyService.insertMentorClassify(mentorClassify));
    }

    /**
     * 修改导师分类
     */
    @ApiOperation(value = "修改导师分类", notes = "修改导师分类详情", tags = {"导师分类管理"})
    //@PreAuthorize("@ss.hasPermi('mentor:classify:edit')")
    @Log(title = "导师分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(HttpServletRequest request,@RequestBody MentorClassify mentorClassify) {
        Long userId = tokenService.getLoginUser(request).getUser().getUserId();
        mentorClassifyService.completeData(mentorClassify, userId, 2);
        return toAjax(mentorClassifyService.updateMentorClassify(mentorClassify));
    }

    /**
     * 删除导师分类
     */
    @ApiOperation(value = "删除导师分类", notes = "删除导师分类详情", tags = {"导师分类管理"})
    //@PreAuthorize("@ss.hasPermi('mentor:classify:remove')")
    @Log(title = "导师分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{mentorClassifyIds}")
    public AjaxResult remove(@PathVariable Long[] mentorClassifyIds) {
        return toAjax(mentorClassifyService.deleteMentorClassifyByMentorClassifyIds(mentorClassifyIds));
    }
}
